<template>
	<view class="">
		<view class="intro">
			<view class="tips">尚食斋</view>
		</view>
		<view class="bottom">
			<button type="primary" size="default" class="login-btn" @click="login">
				<image src="/static/login/wechat.png"></image>
				微信授权登录
			</button>
			<!-- <button type="primary" size="default" class="login-btn" v-if="appProperties.testUserLoginEnabled || $config.env == 'dev'" @tap="showPop = true" :disabled="logining">测试号登录</button> -->

			<view style="position: fixed;top:0px;width:100vw;height:100vh;" v-if="showPop" @tap="showPop = false">
			</view>
			<view v-if="showPop"
				style="position: fixed;top: 20vh;width: 90vw;height: 35vh; background-color: #cccccc;padding: 30px;">
				<!--弹窗-->
				<view title="删除图片需要管理员密码" confirm-text="确定" cancel-text="取消" @cancel="cancelPop" @confirm="confirmPop">
					<input v-model="secretPassword" type="text"
						style="height: 50px;border: 1px solid #878889; margin: 10px;" placeholder="请输入密码" />
					<button @tap="loginForTest">登录</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const defaultAvatarUrl =
		'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
	export default {
		data() {
			return {
				title: 'Hello',
				userInfo: {
					avatarUrl: defaultAvatarUrl,
					nickName: 'admin',
				},
				
			}
		},
		onLoad() {

		},
		methods: {
			//todo 这里写微信登录的逻辑
			login() {
				const that = this
				uni.getUserInfo({
					provider: 'weixin',
					success: (res) => {
						that.userInfo.avatarUrl=res.userInfo.avatarUrl
						that.userInfo.nickName=res.userInfo.nickName
						// console.log(that.userInfo.nickName)
						
						uni.login({
							success: (res) => {
								// console.log(res.code+"1111222")
								this.$https({
									url:'/login',
									method:"post",
									data:{
										code:res.code,
										avatar:this.userInfo.avatarUrl,
										nickName:this.userInfo.nickName
									},	
									success:res=>{
										this.$store.commit("login",res.data)
										uni.reLaunch({
												url: '/pages/stores/stores'
											});
									}
								})
								
							}
						})
					}
				})

			}

		}
	}
</script>



<style lang="scss" scoped>
	.intro {
		width: 100%;
		height: 50vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-evenly;
		// font-size: $font-size-base;


		image {
			width: 200rpx;
			height: 200rpx;
		}

		.tips {
			line-height: 72rpx;
			font-size: 30rpx;
			text-align: center;
		}
	}

	.bottom {
		height: 20vh;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		padding: 0 40rpx;


		.login-btn {
			width: 100%;
			border-radius: 50rem !important;
			display: flex;
			background-color: #ffc200;
			align-items: center;
			justify-content: center;
			padding: 10rpx 0;

			image {
				width: 36rpx;
				height: 30rpx;
				margin-right: 10rpx;
			}
		}

		.row {
			.grid {
				width: 20%;

				image {
					width: 60rpx;
					height: 60rpx;
					margin-bottom: 10rpx;
				}
			}
		}
	}
</style>